package com.study.favorite.mapper;

import com.study.favorite.pojo.Tag;
import lombok.Data;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface TagMapper {

    // 增
    @Insert("insert into tag values (default, #{tname}, 1)")
    @Options(useGeneratedKeys = true,keyColumn = "tid",keyProperty = "tid")
    int insert(Tag tag);

    // 改
    @Update("update tag set tcount=tcount+1 where tname=#{tname}")
    int updateCount(String tag);

    // 查
    @Select("select * from tag")
    @Results(
            id = "rm1",
            value = {
                    @Result(column = "tid", property = "tid", id = true),
                    @Result(column = "tid", property = "fList",
                    // 这里不配延迟加载， 因为返回是所有的分类和链接，
                    many = @Many(select = "com.study.favorite.mapper.FavoriteMapper.selectByTid")
                    )
            }

    )
    List<Tag> selectAll();

    // 测试用的
    @Select("select * from tag where tname=#{tname}")
    Tag selectByTname(String tname);



}
